﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="InsertScores.aspx.cs" Inherits="InsertScores" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Insert Scores</title>
        
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <link rel="stylesheet" href="css/jquery.mobile-1.2.0.css" />
      <script language="javascript" type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
      <script language="javascript" type="text/javascript" src="js/jquery.mobile-1.2.0.min.js"></script>
	 
 </head>
<body>
    <form id="form1" runat="server">   
 <script type="text/javascript">

     $(document).ready(function () {
         $(document).bind('mobileinit', function () {
             $.mobile.loader.prototype.options.text = "loading";
             $.mobile.loader.prototype.options.textVisible = false;
             $.mobile.loader.prototype.options.theme = "a";
             $.mobile.loader.prototype.options.html = "";
         });
     });
     
    
     function Insert() {

         var Score = $("#txt_Score").val(); ;
         var TounamentId = parseInt(document.getElementById("cmb_QTour")[document.getElementById("cmb_QTour").selectedIndex].value);
         var Tournament = document.getElementById("cmb_QTour")[document.getElementById("cmb_QTour").selectedIndex].text;
         var PlayerId = parseInt(document.getElementById("cmbPlayer")[document.getElementById("cmbPlayer").selectedIndex].value);
         var Player = document.getElementById("cmbPlayer")[document.getElementById("cmbPlayer").selectedIndex].text;
         var MachineId = parseInt(document.getElementById("cmbMachine")[document.getElementById("cmbMachine").selectedIndex].value);
         var Machine = document.getElementById("cmbMachine")[document.getElementById("cmbMachine").selectedIndex].text;
       
         if (Score == '') {
             $("#popupmessage").html("Are you stupid?, Please enter the score correctly!");
             $("#popupheader").html("Error");             
             $("#message").popup("open")
             return;
         }
         if (Score < 0) {
             $("#popupmessage").html("Can not erase scores from here. Talk to the tournament director.");
             $("#popupheader").html("Error");    
             $("#message").popup("open")
             return;
         }
         //dialogmessage
         $("#dialogmessage").html(htmlForTextWithEmbeddedNewlines(Tournament + "\n" + Player + "\n" + Machine + "\n" + "SCORE: " + Score));
         
         $("#popupDialog").popup("open")

        
        
     }

     function ConfirmIt() {
        
         $("#popupDialog").popup("close");
         //$.mobile.loading('show', { theme: "b", text: "Conecting with the server... please wait.", textonly: true });
         var Score = $("#txt_Score").val(); 
         var TounamentId = parseInt(document.getElementById("cmb_QTour")[document.getElementById("cmb_QTour").selectedIndex].value);
         var PlayerId = parseInt(document.getElementById("cmbPlayer")[document.getElementById("cmbPlayer").selectedIndex].value);
         var MachineId = parseInt(document.getElementById("cmbMachine")[document.getElementById("cmbMachine").selectedIndex].value);
       
         var res = InsertScores.InsertPlayerScore(Score, TounamentId, PlayerId, MachineId);
         //$.mobile.loading('hide');
         if (res.value < 0) {
             $("#popupmessage").html("Unable to insert the score");
             $("#popupheader").html("Error");
             $("#message").popup("open")
            
         } else {
             $("#popupmessage").html("\n\nInsert score sucessfully!\n\n");
             $("#popupheader").html("You are a fucking crack!");            
             $("#btn_send").attr("value", "INSERTED");
             $('[type="button"]').button('disable');
             $('[type="button"]').button('refresh');
             $("#txt_Score").attr("disabled", true); 
             $("#message").popup("open");                  
         }
        
     }

     function Check() {
         var name_element = document.getElementById("ResponseMessage");
         if (name_element.value != "") {
             alert(name_element.value);
             name_element.value = "";
         } else {
             alert(name_element.value);
         }
     }

     function htmlForTextWithEmbeddedNewlines(text) {
         var htmls = [];
         var lines = text.split(/\n/);
         for (var i = 0; i < lines.length; i++) {            
             htmls.push(
            jQuery(document.createElement('div')).text(lines[i]).html()
        );
         }
         return htmls.join("<br>");
     }


      </script>
     <div data-role="page" data-theme="b">
     <div data-role="popup" id="message" data-transition="flip" data-theme="e" data-overlay-theme="a" class="ui-content">
	<div data-role="header" data-position-to="window" data-theme="a" class="ui-corner-top">
    
				<h1 id="popupheader">Error</h1>
			</div>
            <br /><br />
    <p id="popupmessage">This is a completely basic popup, no options set.</p>
    <br /><br />
    <a href="#" data-role="button" data-rel="back" data-theme="c" data-icon="check">Close</a>
</div>
     <div data-role="popup" data-position-to="window" id="about" data-transition="flip" data-theme="d" style="max-width:400px;"  data-overlay-theme="a" class="ui-content">
	<div data-role="header" data-theme="d" class="ui-corner-top">
    <center>
				<h1 id="H1">About &copy; PTSS</h1>
			</div>
            <br /><br />
    <p id="p5"><b>PTSS Mobile</b></p>
    <p id="p1"><b>Developed by:</b> Fernando Beltrán</p>
    <p id="p2"><b>Supported by:</b> TMAP (Torneo Madrileño de Pinballs), Torneo Ciudad de Silla, TEP (Torneo Español de Pinballs), EPC (European Pinball Championship), TPV (Torneo de Pinball de Villena).</p>
    <p id="p3"><b>Version:</b> 0.8.0 (b)</p>
    <p id="p4"><b>Web:</b> www.aacppinball.com</p>
    <br /><br /></center>
    <a href="#" data-role="button" data-rel="back" data-theme="d" data-icon="check">Close</a>
</div>
<div data-role="popup" data-position-to="window" id="popupDialog" data-overlay-theme="a" data-theme="c" style="max-width:400px;" class="ui-corner-all">
			<div data-role="header" data-theme="a" class="ui-corner-top">
				<h1>Confirm score</h1>
			</div>
			<div data-role="content" data-theme="e" class="ui-corner-bottom ui-content">
				<h3 class="ui-title">¡Please confirm the data with the player!</h3>
				<p id="dialogmessage">This action cannot be undone.</p>
				<center><a href="#" data-role="button" data-inline="true" data-rel="back" data-theme="c" data-icon="delete">Cancel</a>    
				<input data-icon="check" data-theme="b" data-inline="true" type="button" onclick="ConfirmIt()" value="Confirm" />
                </center>
			</div>
		</div>


	<div data-role="header" data-theme="b">
       <a href="#about" data-icon="info" data-rel="popup">About</a>
		<h1>PTTS Mobile 0.8</h1>
        <a href="InsertScores.aspx" data-icon="refresh">Refresh</a>
	</div><!-- /header -->

	<div data-role="content" data-theme="e">	   
    <div style="text-align:left;margin:8px;">
       <!--  <label for="Qualify">Qualify</label>-->
       <asp:RadioButton Visible="false" ID="Qualify" GroupName="Fase" runat="server" 
                Checked="true" AutoPostBack="True" oncheckedchanged="Qualify_CheckedChanged" />
       <!-- <label for="Playoffs">Playoffs</label>--><asp:RadioButton ID="Playoffs" Visible="false" GroupName="Fase" runat="server" 
                AutoPostBack="True" oncheckedchanged="Playoffs_CheckedChanged" />
        <label for="cmb_QTour">Select Tournament:</label>
        <asp:DropDownList ID="cmb_QTour" runat="server" OnSelectedIndexChanged="cmb_QTour_SelectedIndexChanged" AutoPostBack="True">
        </asp:DropDownList>
        Select Player:
        <asp:DropDownList ID="cmbPlayer" runat="server" OnSelectedIndexChanged="cmbPlayer_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>
     
        Select Pinball:       
        <asp:DropDownList ID="cmbMachine" runat="server" OnSelectedIndexChanged="cmbMachine_SelectedIndexChanged" AutoPostBack="True">
        </asp:DropDownList>
     
        Score:      
        <asp:TextBox ID="txt_Score" runat="server" Text=""></asp:TextBox>
        <asp:HiddenField ID="ResponseMessage" runat="server" Value=""  />
        <asp:CheckBox ID="IsJoker" Visible="false" Enabled="false" Text="Is Joker" runat="server" />
   
        <input type="button" ID="btn_send" data-icon="check" runat="server" Font-Bold="true" value="SEND SCORE" onclick="Insert()" />
        <asp:Label ID="lbl_server" CssClass="labelcss"  Visible="false" runat="server" Text="Label"></asp:Label>
        </div>
       
        </div><!-- /content -->

	<div data-role="footer" data-theme="b">
		<h4>Developed by &copy; Fernando Beltrán 2013</h4>
	</div><!-- /footer -->
</div><!-- /page -->
  
    </form>
   
</body>
</html>
